from flask import Flask
from app.config import Config
from app.exts import database, mail
# 测试数据库是否连接成功时使用
from sqlalchemy import text
from app.blueprintes import bp


def creat_app():
    app = Flask(__name__)

    # 配置信息
    app.config.from_object(Config)

    # 数据库初始化
    database.init_app(app)
    mail.init_app(app)

    # 测试数据库是否连接成功代码，输出(1,)则为连接成功
    # with app.app_context():
    #     with database.engine.connect() as conn:
    #         rs = conn.execute(text("select 1"))
    #         print(rs.fetchone())

    app.register_blueprint(bp)

    return app
